#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "methodget.h"

void PrintError(const int err)
{
	const char * ERROR_MESSAGES[3] = {
        "This parameter is not found or value is empty!",
        "The parameter value is empty!",
        "The query string is missing!"
    };
    if ((err >= 1) && (err <= 3))
    {
        printf(ERROR_MESSAGES[err - 1]);
    }
}

void main(void)
{
	printf("Content-Type: text/plain;charset=utf-8\n\n");

	int err = 0;
	char * data = getenv("QUERY_STRING");
	if (*data == '\0')
	{
		err = 3;
		PrintError(err);
		return;
	}
	char newData[255];
	AddSpecialSymbols(data, newData, '?', 0);
	char value[255];
	GetValue("name", newData, value, &err);
	if ((value) && (err == 0))
	{
		printf("Hello, Dear %s!", value);
	}
	else
	{
		PrintError(err);
	}
}